package com.ruoyi.cbfa.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cbfa.mapper.InsurancePlanMapper;
import com.ruoyi.cbfa.domain.InsurancePlan;
import com.ruoyi.cbfa.service.IInsurancePlanService;

/**
 * 参保方案Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-29
 */
@Service
public class InsurancePlanServiceImpl implements IInsurancePlanService 
{
    @Autowired
    private InsurancePlanMapper insurancePlanMapper;

    /**
     * 查询参保方案
     * 
     * @param id 参保方案主键
     * @return 参保方案
     */
    @Override
    public InsurancePlan selectInsurancePlanById(Long id)
    {
        return insurancePlanMapper.selectInsurancePlanById(id);
    }

    /**
     * 查询参保方案列表
     * 
     * @param insurancePlan 参保方案
     * @return 参保方案
     */
    @Override
    public List<InsurancePlan> selectInsurancePlanList(InsurancePlan insurancePlan)
    {
        return insurancePlanMapper.selectInsurancePlanList(insurancePlan);
    }

    /**
     * 新增参保方案
     * 
     * @param insurancePlan 参保方案
     * @return 结果
     */
    @Override
    public int insertInsurancePlan(InsurancePlan insurancePlan)
    {
        return insurancePlanMapper.insertInsurancePlan(insurancePlan);
    }

    /**
     * 修改参保方案
     * 
     * @param insurancePlan 参保方案
     * @return 结果
     */
    @Override
    public int updateInsurancePlan(InsurancePlan insurancePlan)
    {
        return insurancePlanMapper.updateInsurancePlan(insurancePlan);
    }

    /**
     * 批量删除参保方案
     * 
     * @param ids 需要删除的参保方案主键
     * @return 结果
     */
    @Override
    public int deleteInsurancePlanByIds(Long[] ids)
    {
        return insurancePlanMapper.deleteInsurancePlanByIds(ids);
    }

    /**
     * 删除参保方案信息
     * 
     * @param id 参保方案主键
     * @return 结果
     */
    @Override
    public int deleteInsurancePlanById(Long id)
    {
        return insurancePlanMapper.deleteInsurancePlanById(id);
    }

    @Override
    public Map<String, List<Map<String, Object>>> getInsuranceDetailsByName(String name) {
        InsurancePlan plan = insurancePlanMapper.selectCategoryIdsByName(name);
        if (plan == null) {
            return Collections.emptyMap();
        }

        Map<String, List<Map<String, Object>>> result = new HashMap<>();
        result.put("shebaoDetails", insurancePlanMapper.selectShebaoDetails(plan.getCategoryShebaoId()));
        result.put("gjjDetails", insurancePlanMapper.selectGjjDetails(plan.getCategoryGjjId()));

        return result;
    }
    @Override
    public List<String> selectDistinctPlanNames() {
        return insurancePlanMapper.selectDistinctPlanNames();
    }
    @Override
    public List<Map<String, Object>> selectDistinctPlanNamesWithIds() {
        return insurancePlanMapper.selectDistinctPlanNamesWithIds();
    }
}
